package br.xraylol.service;

import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import br.xraylol.client.LolStaticDataClient;
import br.xraylol.custom.list.ChampionList;

@Service
public class ChampionService {
	
	@Autowired
	private LolStaticDataClient lolStaticDataClient;
	
	@Cacheable("xraylol")
	public Integer findIdByName(String championName) {
		ChampionList champions = lolStaticDataClient.findChampions();
		Integer id = null;
		
		for (Entry<String, String> championsIds : champions.getKeys().entrySet()) {
			if (championName.equals(championsIds.getValue())) {
				id = Integer.parseInt(championsIds.getKey());
				break;
			}
		}
		
		return id;
	}
}
